<template>
	<view class="tabs">
		<view style="height: 70rpx;" class="page-section-spacing">
			<view class="scroll-view-item_H" v-for="(item,index) in tabList" @tap="changeTab(index)">
				<view class="animate__animated" hover-class="animate__rubberBand"
					:class="index == isActive ? 'active' :''">
					{{item.name}}
				</view>
				<view class="" :class="index == isActive ? 'line' :''"></view>
			</view>
		</view>
		<view class="page-section-spacing">
			<scroll-view :refresher-triggered=refresherTriggered :refresherThreshold=refresherThreshold
				@refresherrefresh='refresherrefresh()' refresher-background="#FFFFFF"  @scrolltolower='nextPage()'
				 
				 lower-threshold="500" class="" scroll-y :style="{height: orderHeight+'px'}">
				<view class="card box-c animated fadeIn" hover-class="tada" v-if="!isNull" v-for="item in orderList" >
					<view class="head box d-ai-c d-jc-sb" >
						<view class="box d-ai-c">
							<text class="shopname">{{item.shopName}}</text>
							<text class="" style="margin-left: 10rpx; font-size: 24rpx ;color: #999999;" class="iconfont iconqianjin"></text>
						</view>
						<view class="">
							<text class="" style="color:#FF5551" v-if="item.status===0&&item.failStatus===0">已报名</text>
							<text class="" style="color:#FF7E51" v-if="item.status===1">待付款</text>
							<text class="" style="color:#6680FF" v-if="item.status===9">退款</text>
							<text class="" style="color:#FF5551" v-if="item.status===0&&item.failStatus===1">退款中</text>
							<text class="" style="color:#FF5551" v-if="item.status===0&&item.failStatus===2">退款失败</text>
							<text class="" style="color:#FF5551" v-if="item.status===0&&item.failStatus===3">退款成功</text>
							<text class="" style="color:#999999" v-if="item.status===2">订单已取消</text>
						</view>
					
					</view>
					<view class="box"  @tap="getclassDetail(item.ordersNumber)">
						<view class="boximg">
							<image class="shop-logo" :src="item.classImage"  />
						</view>
						<view class="list-1">
							<view class="">{{item.className}}</view>
							<view class="">
								<image class="teacherimg" src="../../static/images/lesson/teacher@2x.png" mode=""></image>
								<text class="teachername">{{item.teacherName}}老师</text>
							</view>
						</view>
					</view>
				</view>	
				<view v-if="isNull" class="order_null">
					<image src="../../static/images/order/order_null.png"></image>
					<text>暂时还没有订单~</text>
					
				</view>
			</scroll-view>
		</view>
		
	</view>

	</view>
</template>

<script>
	import uQRCode from '@/js_sdk/Sansnn-uQRCode/uqrcode.js'
	export default {
		data() {
			return {
				payState: '',
				pupPrice: 0,
				pupOrderNo: [],
				orderHeight: 500,
				isActive: 0,
				tabList: [{
					id: "1",
					name: '全部'
				}, {
					id: "2",
					name: '待付款'
				}, {
					id: "3",
					name: '已报名'
				}, {
					id: "4",
					name: '退款'
				} ],
				orderList: [],
				userId: 1,
				isNull: false,
				hasNextPage: true,
				refresherThreshold: 50,
				refresherTriggered: false,
				_refresherTriggered: false,
				pageNum:1,
				pageSize:5

			}
		},
		onReady() {
			let that = this;
			uni.getSystemInfo({ //调用uni-app接口获取屏幕高度
				success(res) { //成功回调函数
					that.orderHeight = res.windowHeight - uni.upx2px(90) //windoHeight为窗口高度，主要使用的是这个

				}
			})
		},
		onShow() {
			let carData = ''
			let _this = this
			uni.$on("carData", (rel) => {
				carData = rel
				if (carData == 1) {
					_this.isActive = 0
					console.log(carData)
					_this.changeTab(carData)
				} else {
					console.log(_this.payState)
					_this.getOrderList(_this.payState)
				}
			})
		
		},
		onLoad(parameter) {
			console.log(parameter.payState)
			this.isActive = parameter.payState == undefined ? 0 : parameter.payState
			if (parameter.payState == undefined || parameter.payState == 0) {
				this.payState = ''
			} else if (parameter.payState == 1) {
				this.payState = 1
			} else if (parameter.payState == 2) {
				this.payState = 0
			} else if (parameter.payState == 3) {
				this.payState = 9
			} 

			this.getOrderList(this.payState)

		},
		methods: {
			async make(pupOrderNo) {
				// 回调方式
				uQRCode.make({
					canvasId: 'qrcode',
					componentInstance: this,
					text: pupOrderNo,
					size: 250,
					margin: 0,
					backgroundColor: '#ffffff',
					foregroundColor: '#000000',
					fileType: 'jpg',
					correctLevel: uQRCode.errorCorrectLevel.H,
					success: res => {
						console.log(res)
					}
				})		
			},
			refresherrefresh() {
				console.log("自定义下拉刷新被触发");
				let _this = this;
				if (_this._refresherTriggered) {
					return;
				}
				_this._refresherTriggered = true;
				//界面下拉触发，triggered可能不是true，要设为true
				if (!_this.refresherTriggered) {
					_this.refresherTriggered = true;
				}
				_this.getClassOrdersList(_this.payState)
				setTimeout(() => {
					_this.refresherTriggered = false; //触发onRestore，并关闭刷新图标
					_this._refresherTriggered = false;
				}, 1500)
			
			},
			getclassDetail(a) {
				console.log(a)
					uni.navigateTo({
						url: './lessonDetail?ordersNumber='+a,
						success: res => {},
						fail: () => {},
						complete: () => {}
					});
			},
			nextPage() {
				let _this = this
				console.log("====出发底部===")
				console.log("====出发底部===" + this.pageNum)
				console.log("====出发底部===" + this.hasNextPage)
				if (this.hasNextPage) {
					this.pageNum = this.pageNum + 1
					this.$api.getClassOrdersList({
						status: this.payState
					}, this.pageNum, this.pageSize).then((res) => {
						if (res.data.code == 200) {
							// console.log("-----"+JSON.stringify(this.orderList))
							for (var i = 0; i < res.data.dataMap.list.length; i++) {
								this.orderList.push(res.data.dataMap.list[i])
							}
							this.hasNextPage = res.data.dataMap.hasNextPage
			
						}
					})
				}
			
			},
			//获取订单列表
			getOrderList(payState) {
				this.orderList = []
				this.pageNum = 1
				console.log(this.payState)
				let _this = this
				this.$api.getClassOrdersList({
					status: this.payState
				}, _this.pageNum,_this.pageSize).then((res) => {
					if (res.data.code == 200) {
						console.log(res.data.dataMap)
						_this.orderList = res.data.dataMap.list
						_this.isNull = _this.orderList.length < 1 ? true : false
						_this.hasNextPage = res.data.dataMap.hasNextPage
					}
				})
			},
			
			//点击事件改变swiper
			changeTab(active) {
				this.isActive = active
				if (active == 0) { 
					this.payState = ''
				} else if (active == 1) {
					this.payState = 1
				} else if (active == 2) {
					this.payState = 0
				} else if (active == 3) {
					this.payState = 9
				} 
				console.log('状态'+this.payState)
				this.getOrderList(this.payState)

			},


		}
	}
</script>

<style scoped>
	.teachername{
		margin-left: 7rpx;
	}
	.teacherimg{
		width: 24rpx;
		height:22rpx
	}
	.shopname{
		font-size: 26rpx;
	}
	.head{
		font-size: 30rpx;
		color:#666666;
		height: 60rpx;
		position: relative;
		border: 1rpx solid white;
	}
	.head-status{
		font-size: 23rpx;
		position: absolute;
		right: 15rpx;
	}
	.cancel {
		color: #999999;
	}
	.beihuo{
		color: #6680ff;
	}
	.peisong{
		color: #FF5551;
		
	}
	.songda{
		color: #999;
	}
	.canvas {
		height: 230px;
		width: 230px;
		margin: 5rpx 0;
	}

	.btn-shop-list {
		background-color: #FF5551;
		border-radius: 50rpx;
		width: 200rpx;
		color: #FFFFFF;
		line-height: 75rpx;
		margin-top: 40rpx;
	}

	.order_null {
		display: flex;
		width: 100%;
		flex-direction: column;
	}

	.order_null text {
		margin: 0 auto;
		color: #c8c8c8;
	}

	.order_null image {
		margin: 60rpx auto;
		width: 250rpx;
		height: 250rpx;
	}

	.qrcode-title {
		margin: 0 auto;
		color: #b0b0b0;
	}

	.pop-cart-list-5 text {
		font-size: 36rpx;
		font-weight: 600;
		color: #FF5551;
		padding: 20rpx 0 0 0;

	}

	.pop-cart-list-3 text {
		font-size: 40rpx;
		font-weight: 600;
		padding: 5rpx 0 20px 0;

	}

	.pop-cart-list-2{
		color: #a3a3a3;
		padding-bottom: 15rpx;
	}

	.pop-cart-list-1 text:first-child {
		color: #cecece;

	}

	.pop-cart-list-1 text:last-child {
		color: #5890ff;

	}

	.line-pop {
		height: 2rpx;
		background-color: #f0f0f0;
		width: 100%;
		margin: auto;
		border-radius: 24rpx;
	}

	.djc-s-a {
		display: flex;
		justify-content: space-between;
		align-items: center;

	}

	.djc-c-a {
		display: flex;
		justify-content: center;
		align-items: center;

	}

	.pop-cart {
		width: 550rpx;
		height: auto;
		background-color: #ffffff;
		padding: 20rpx;
		border-radius: 15rpx;
	}

	.list-1 {
		padding: 0 0 0 20rpx;
	}

	.list-1 view:nth-child(1) {
		font-weight: 600;
		margin-top: -7rpx;
	}

	.list-1 view:nth-child(2) {
		font-size: 24rpx;
		margin-top: 53rpx;
		color: #9e9e9e;
	}

	.info {
		width: 680rpx;
		margin: 0 auto;
		padding-top: 15rpx;

	}

	.pay {
		padding: 15rpx 0rpx 0rpx 0rpx;
		color: #FF5551;
		font-weight: 500;
		font-size: 30rpx;
	}

	.catCode {
		padding: 15rpx 0rpx 0rpx 0rpx;
		color: #5890ff;
		font-weight: 500;
		font-size: 30rpx;
	}

	.aj {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.info {
		display: flex;
		justify-content: space-between;
	}

	.info text:nth-child(1) {
		flex: 1.8;
	}

	.info text:nth-child(2) {
		flex: 1;
		color: #959595;
	}

	.info text:nth-child(3) {
		flex: 1.4;
		text-align: center;
	}

	.last text:first-child {
		font-weight: 600;

	}

	.last text:last-child {
		font-weight: 600;
		color: #FF5551;

	}

	.shop-logo {
		width: 180rpx;
		height: 100%;
		border-radius: 10rpx;
	}
     .boximg{
		width: 180rpx;
		height: 130rpx;
		border-radius: 10rpx;
	 }
	.card {
		display: flex;
		width: 650rpx;
		height: 230rpx;
		margin: 10rpx auto;
		background-color: #ffffff;
		border-radius: 10rpx;
		padding: 7rpx 30rpx;
		margin-bottom: 30rpx;


	}

	.swiper {
		width: 100%;
	}

	.page-section-spacing {
		background-color: #f3f3f3;
		padding-top: 10rpx;
		display: flex;
		justify-content: space-between;
	}

	.line {
		height: 8rpx;
		background-color: #FF5551;
		width: 50%;
		margin: auto;
		border-radius: 50rpx;
		margin-top: 5rpx;
	}

	.line-gray {
		height: 1rpx;
		width: 660rpx;
		background-color: #f0f0f0;
		margin: auto;
		border-radius: 24rpx;
		z-index: 99;
	}

	.scroll-view_H {
		white-space: nowrap;
		width: 90%;
	}

	.scroll-view-item_H>view {
		font-size: 33rpx;
		
	}

	.scroll-view-item_H {
		display: inline-block;
		width: 150rpx;
		height: 75rpx;
		line-height: 75rpx;
		text-align: center;
		font-size: 34rpx;
		/* margin-left: 28rpx; */
	}

	,
	.tab-bar {
		/* #ifdef APP-PLUS */
		width: 750rpx;
		/* #endif */
		height: 42px;
		flex-direction: row;
		/* #ifndef APP-PLUS */
		white-space: nowrap;
		/* #endif */
	}

	,
	.tabs {
		flex: 1;
		flex-direction: column;
		background-color: #ffffff;
	}

	,
	.title-1 {}

	.score {
		color: #ff0000;
		position: absolute;
		right: 50rpx;

	}

	.del-order {
		right: 200rpx;
		padding: 0rpx 15rpx;

	}

	.sub-order {
		color: #ffffff;
		padding: 0rpx 15rpx;
		right: 30rpx;
	}

	.image_icon {
		width: 140upx;
		height: 140upx;
	}

	.active {
		color: #a7a7a7;
	}

	.title {
		padding: 10rpx;
		font-size: 28rpx;
		width: 150rpx;
		text-align: center;

	}
	.box {
		flex-direction: row;
		display: flex;
		margin-top: 10rpx;
	}

	.box-c {
		flex-direction: column;
		display: flex;
	}
</style>

